from django.db import models
from django.contrib.auth.models import AbstractUser

from datetime import datetime


class UserProfileModel(AbstractUser):
    """自定义用户模型，继承AbstractUser"""
    nick_name = models.CharField(verbose_name='昵称', max_length=50, blank=True, null=True, default='')
    birday = models.DateField(verbose_name='生日', blank=True, null=True, default=datetime.now())
    gender = models.IntegerField(verbose_name='性别', choices=((0, '女'), (1, '男')), default=0)
    mobile = models.CharField(verbose_name='手机号码', max_length=11, blank=True, null=True, default='')
    address = models.CharField(verbose_name='地址', max_length=100, blank=True, null=True, default='')
    image = models.ImageField(verbose_name='头像', upload_to='user_image/%Y/%m', default='', max_length=100)

    class Meta:
        verbose_name = '用户信息'
        verbose_name_plural = verbose_name


class EmailVerifyRecord(models.Model):
    """邮箱验证码模型"""
    code_send_type = (('register', '注册'), ('forget', '找回密码'), ('update_email', '修改邮箱'))

    code = models.CharField(verbose_name='验证码', max_length=20)
    email = models.EmailField(verbose_name='邮箱', max_length=100)
    send_type = models.CharField(verbose_name='验证码类型', max_length=50, choices=code_send_type, default='register')
    send_time = models.DateTimeField(verbose_name='发送时间', default=datetime.now())

    class Meta:
        verbose_name = '邮箱验证码'
        verbose_name_plural = verbose_name


class BannerModel(models.Model):
    """轮播图模型"""
    title = models.CharField(verbose_name='标题', max_length=100, blank=True, null=True)
    image = models.ImageField(upload_to='banner/%Y/%m', verbose_name='轮播图')
    url = models.URLField(verbose_name='访问地址', max_length=200, blank=True, null=True, default='https://www.baidu.com')
    index = models.IntegerField(verbose_name='顺序', default=1)
    add_time = models.DateTimeField(verbose_name='添加时间', default=datetime.now())

    class Meta:
        verbose_name = '轮播图'
        verbose_name_plural = verbose_name


